{% extends "zato/index.html" %}

{% block html_title %}Cassandra connections{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
{% endblock %}

{% block "extra_js" %}

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/definition/cassandra.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',
            'name',
            '_is_active',
            'contact_points',
            'port',
            '_change_password,',
            '_edit',
            '_delete',
            'id',
            'is_active',
            'username',
            'default_keyspace',
            'cql_version',
            'tls_ca_certs',
            'tls_client_cert',
            'tls_client_priv_key'
        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Cassandra connections</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

{% include "zato/search-form.html" with page_prompt="Show connections"%}


    {% if cluster_id %}

        <div class='page_prompt' style="clear:left">
            <a href="javascript:$.fn.zato.definition.cassandra.create()">Create a new Cassandra connection</a>
        </div>

        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th><a href="#">Name</a></th>
                        <th><a href="#">Active</a></th>
                        <th><a href="#">Contact points</a></th>
                        <th><a href="#">Port</a></th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>
                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>
                        <td>{{ item.name }}</td>
                        <td>{{ item.is_active|yesno:'Yes,No' }}</td>
                        <td>{{ item.contact_points }}</td>
                        <td>{{ item.port }}</td>
                        <td><a href="javascript:$.fn.zato.data_table.change_password('{{ item.id }}')">Change password</a></td>
                        <td><a href="javascript:$.fn.zato.definition.cassandra.edit('{{ item.id }}')">Edit</a></td>
                        <td><a href="javascript:$.fn.zato.definition.cassandra.delete_('{{ item.id }}')">Delete</a></td>
                        <td class='ignore item_id_{{ item.id }}'>{{ item.id }}</td>
                        <td class='ignore'>{{ item.is_active }}</td>
                        <td class='ignore'>{{ item.username|default:"" }}</td>
                        <td class='ignore'>{{ item.default_keyspace }}</td>
                        <td class='ignore'>{{ item.cql_version|default:"" }}</td>
                        <td class='ignore'>{{ item.tls_ca_certs|default:"" }}</td>
                        <td class='ignore'>{{ item.tls_client_cert|default:"" }}</td>
                        <td class='ignore'>{{ item.tls_client_priv_key|default:"" }}</td>
                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='11'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>

{% include "zato/paginate/action-panel.html" %}

        <div id="create-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "definition-cassandra-create" %}" method="post" id="create-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle">Name</td>
                            <td>{{ create_form.name }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Active</td>
                            <td>{{ create_form.is_active }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Contact points</td>
                            <td>{{ create_form.contact_points }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Port
                                <br/>
                                <span class="form_hint">(Default: {{ default_port }})</span>
                            </td>
                            <td>{{ create_form.port }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Executor pool size
                                <br/>
                                <span class="form_hint">(Default: {{ default_exec_size }})</span></td>
                            <td>{{ create_form.exec_size }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Protocol version
                                <br/>
                                <span class="form_hint">(Default: {{ default_proto_version }})</span></td>
                            <td>{{ create_form.proto_version }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">CQL version</td>
                            <td>{{ create_form.cql_version }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Default keyspace</td>
                            <td>{{ create_form.default_keyspace }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Username</td>
                            <td>{{ create_form.username }}</td>
                        </tr>
                        <!--
                        <tr>
                            <td style="vertical-align:middle">TLS CA certs</td>
                            <td>{{ create_form.tls_ca_certs }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">TLS client cert</td>
                            <td>{{ create_form.tls_client_cert }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">TLS client priv key</td>
                            <td>{{ create_form.tls_client_priv_key }}</td>
                        </tr>
                        -->
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" name="is_active" value="on" />
                    <input type="hidden" id="cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                </form>
            </div>
        </div>

        <div id="edit-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "definition-cassandra-edit" %}" method="post" id="edit-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle">Name</td>
                            <td>{{ edit_form.name }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Active</td>
                            <td>{{ edit_form.is_active }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Contact points</td>
                            <td>{{ edit_form.contact_points }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Port
                                <br/>
                                <span class="form_hint">(Default: {{ default_port }})</span>
                            </td>
                            <td>{{ edit_form.port }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Executor pool size
                                <br/>
                                <span class="form_hint">(Default: {{ default_exec_size }})</span></td>
                            <td>{{ edit_form.exec_size }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Protocol version
                                <br/>
                                <span class="form_hint">(Default: {{ default_proto_version }})</span></td>
                            <td>{{ edit_form.proto_version }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">CQL version</td>
                            <td>{{ edit_form.cql_version }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Default keyspace</td>
                            <td>{{ edit_form.default_keyspace }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Username</td>
                            <td>{{ edit_form.username }}</td>
                        </tr>
                        <!--
                        <tr>
                            <td style="vertical-align:middle">TLS CA certs</td>
                            <td>{{ edit_form.tls_ca_certs }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">TLS client cert</td>
                            <td>{{ edit_form.tls_client_cert }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">TLS client priv key</td>
                            <td>{{ edit_form.tls_client_priv_key }}</td>
                        </tr>
                        -->
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                    <input type="hidden" name="is_active" value="on" />
                    <input type="hidden" id="id_edit-cluster_id" name="cluster_id" value="{{ cluster_id }}" />
                    <input type="hidden" id="id_edit-id" name="id" />
                </form>
            </div>
        </div>

        <div id="change_password-div" class='data-popup ignore'>
            <div class="bd">
                <form novalidate action="{% url "definition-cassandra-change-password" %}" method="post" id="change_password-form">
                    <table class="form-data">
                        <tr>
                            <td style="vertical-align:middle">Name</td>
                            <td id="change-password-name"></td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Password</td>
                            <td>{{ change_password_form.password1 }}</td>
                        </tr>
                        <tr>
                            <td style="vertical-align:middle">Confirm password</td>
                            <td>{{ change_password_form.password2 }}
                                <input type="hidden" id="id_change_password-id" name="id" />
                                <input type="hidden" id="id_change_password-cluster_id" name="cluster_id" value='{{ cluster_id}}' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align:right">
                                <input type="submit" value="OK" />
                                <button type='button' onclick='javascript:$.fn.zato.data_table.close(this)'>Cancel</button>
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>

    {% endif %} {% comment %}cluster_id{% endcomment %}

{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
